class ReportsController < ApplicationController

  # To make caching easier, add a line like this to config/routes.rb:
  # map.graph "graph/:action/:id/image.png", :controller => "graph"
  #
  # Then reference it with the named route:
  #   image_tag graph_url(:action => 'show', :id => 42)

  def initialize
    @see = 'supervision'
  end
  
  def index
    @page_title = "Visualisation des statistiques"
  end

  def incident_year
    g = Gruff::Bar.new
    g.theme_rails_keynote
    g.title = "Incident Ouvert/Fermé"
    t = Time.now.years_ago(1).beginning_of_month
    open = []
    closed = []
    month = {}
    13.times do |i| 
      open << Incident.find(:all, :conditions => ['created_at > ? AND created_at < ?', t, t.next_month]).size
      closed << Incident.find(:all, :conditions => ['resolved_at > ? AND resolved_at < ?', t, t.next_month]).size
      month[i] = t.strftime('%B\n%Y') if i.even?
      t = t.next_month
    end

    g.data('ouvert', open)
    g.data('fermé', closed)
    g.labels = month
    send_data(g.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "gruff.png")
  end

end
